<?php

namespace app\api\controller;

use app\admin\model\Workdynamic AS WorkdynamicMdl;

class Workdynamic extends BaseController
{

    /**
     * 列表
     */
    public function getList()
    {
        $param = self::getHttpParam();
        $start = 0;
        $length = 20;

        if (!empty($param->start)) {
            $start = $param->start;
        }
        if (!empty($param->length)) {
            $length = $param->length;
        }

        $where = [
            'status' => 1
        ];
        $list = WorkdynamicMdl::where($where)->order('createDate DESC')->limit($start, $length)->select();
        $total = WorkdynamicMdl::where($where)->count();
        if (empty($list)) {
            return show(config('status.ERROR_STATUS'), self::NOT_DATA, '未查到工作动态');
        }

        foreach ($list as $item) {
            $item['imgList'] = explode(',', $item['imgUrls']);
            unset($item['imgUrls']);
        }

        return showTotal(config('status.SUCCESS_STATUS'), self::MSG_SUCCESS, $list, $total);
    }


    /**
     * 详情
     */
    public function getDetail()
    {
        $param = self::getHttpParam();

        if (empty($param->id)) {
            return show(config('status.ERROR_STATUS'), self::NOT_PARAM, 'id 不能为空');
        }

        $where = [
            'id' => $param->id
        ];
        $item = WorkdynamicMdl::where($where)->find();
        if (empty($item)) {
            return show(config('status.ERROR_STATUS'), self::NOT_DATA, '未查到工作动态');
        }

        $item['imgList'] = explode(',', $item['imgUrls']);
        unset($item['imgUrls']);

        return show(config('status.SUCCESS_STATUS'), self::MSG_SUCCESS, $item);
    }

}